GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9eee63...dbdc9f )
by Florian
01:11
created

Okapi.icon   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $, google, mytrans, window, Cookies, Coordinates, get_cookie_string
7
*/
8
9
10
var Okapi = {};
11
Okapi.m_map = null;
12
Okapi.m_sites = null;
13
Okapi.m_ready = false;
14
Okapi.m_showCache = null;
15
Okapi.m_enabled = false;
16
Okapi.m_popup = null;
17
Okapi.m_popupCacheCode = null;
18
Okapi.m_marker = null;
19
Okapi.m_icons = null;
20
Okapi.m_timer = null;
21
22
23
Okapi.init = function (themap) {
24
    'use strict';
25
26
    this.m_map = themap;
27
    var self = this;
28
29
    google.maps.event.addListener(this.m_map, "center_changed", function () {
30
        self.scheduleLoad();
31
    });
32
    google.maps.event.addListener(this.m_map, "zoom_changed", function () {
33
        self.scheduleLoad();
34
    });
35
};
36
37
38
Okapi.parseLocation = function (s) {
39
    'use strict';
40
41
    var loc = s.split("|"),
42
        lat = parseFloat(loc[0]),
43
        lng = parseFloat(loc[1]);
44
45
    if (Coordinates.valid(lat, lng)) {
46
        return new google.maps.LatLng(lat, lng);
47
    }
48
49
    return null;
50
};
51
52
53
Okapi.setShowCache = function (code) {
54
    'use strict';
55
56
    this.m_showCache = code;
57
};
58
59
60
Okapi.setupSites = function () {
61
    'use strict';
62
63
    if (this.m_sites) {
64
        return;
65
    }
66
67
    var self = this,
68
        main_url = "proxy2.php?url=http://www.opencaching.de/okapi/services/apisrv/installations",
69
        keys = {
70
            "Opencaching.DE" : "YSqPufH82encfJ67ZxV2",
71
            "Opencaching.PL" : "jhRyc6rGmT6XEvxva29B",
72
            "Opencaching.NL" : "gcwaesuq3REu8RtCgLDj",
73
            "Opencaching.US" : "GvgyCMvwfH42GqJGL494",
74
            "Opencache.UK" : "7t7VfpkCd4HuxPabfbHd",
75
            "Opencaching.RO" : "gqSWmVJhZGDwc4sRhyy7"
76
        },
77
        prefixes = {
78
            "Opencaching.DE" : "OC",
79
            "Opencaching.PL" : "OP",
80
            "Opencaching.NL" : "OB",
81
            "Opencaching.US" : "OU",
82
            "Opencache.UK" : "OK",
83
            "Opencaching.RO" : "OR"
84
        };
85
86
    this.m_sites = [];
87
88
    $.ajax({
89
        url: main_url,
90
        dataType: 'json',
91
        success: function (response) {
92
            response.map(function (site) {
93
                if (keys[site.site_name] !== undefined) {
94
                    self.m_sites.push({
95
                        siteid: self.m_sites.length,
96
                        name: site.site_name,
97
                        site_url: site.site_url,
98
                        url: site.okapi_base_url,
99
                        proxy: site.okapi_base_url.startsWith('http:'),
100
                        prefix: prefixes[site.site_name],
101
                        key: keys[site.site_name],
102
                        ignore_user: null,
103
                        markers: {},
104
                        finished: true
105
                    });
106
                }
107
            });
108
109
            self.m_ready = true;
110
            if (self.m_enabled) {
111
                self.scheduleLoad(true);
112
            }
113
            if (self.m_showCache && self.m_showCache !== "") {
114
                self.centerMap(self.m_showCache);
115
                self.m_showCache = null;
116
            }
117
        }
118
    });
119
};
120
121
122
Okapi.setupIcons = function () {
123
    'use strict';
124
125
    if (this.m_icons) {
126
        return;
127
    }
128
129
    this.m_icons = {
130
        "Other": new google.maps.MarkerImage("img/cachetype-1.png"),
131
        "Traditional": new google.maps.MarkerImage("img/cachetype-2.png"),
132
        "Multi": new google.maps.MarkerImage("img/cachetype-3.png"),
133
        "Virtual": new google.maps.MarkerImage("img/cachetype-4.png"),
134
        "Webcam": new google.maps.MarkerImage("img/cachetype-5.png"),
135
        "Event": new google.maps.MarkerImage("img/cachetype-6.png"),
136
        "Quiz": new google.maps.MarkerImage("img/cachetype-7.png"),
137
        "Math/Physics": new google.maps.MarkerImage("img/cachetype-8.png"),
138
        "Moving": new google.maps.MarkerImage("img/cachetype-9.png"),
139
        "Drive-In": new google.maps.MarkerImage("img/cachetype-10.png")
140
    };
141
};
142
143
144
Okapi.icon = function (type) {
145
    'use strict';
146
147
    if (this.m_icons[type] !== undefined) {
148
        return this.m_icons[type];
149
    }
150
151
    return this.m_icons.Other;
152
};
153
154
155
Okapi.guessSiteId = function (code) {
156
    'use strict';
157
158
    code = code.toUpperCase();
159
    var siteid;
160
    for (siteid = 0; siteid < this.m_sites.length; siteid += 1) {
161
        if (code.startsWith(this.m_sites[siteid].prefix)) {
162
            return siteid;
163
        }
164
    }
165
166
    return -1;
167
};
168
169
170
Okapi.centerMap = function (code) {
171
    'use strict';
172
173
    if (!this.m_ready) {
174
        return;
175
    }
176
177
    var siteid = this.guessSiteId(code);
178
    if (siteid < 0) {
179
        return;
180
    }
181
182
    this.showPopup(null, code.toUpperCase(), siteid);
183
};
184
185
186
Okapi.popupCacheCode = function () {
187
    if (!this.m_popup) {
188
        return null;
189
    }
190
191
    var m = this.m_popup.getMap();
192
    if (!m || typeof m === "undefined") {
193
        return null;
194
    }
195
196
    return this.m_popupCacheCode;
197
};
198
199
200
Okapi.createPopupContent = function (code, response) {
201
    'use strict';
202
203
    var content =
204
        '<a href="' + response.url + '" target="_blank">' + code + ' <b>' + response.name + '</b></a><br />'
205
        + '<table class="cache-popup">'
206
        + '<tr><td>' + mytrans("geocache.owner") + '</td><td>' + '<a href="' + response.owner.profile_url + '" target="_blank"><b>' + response.owner.username + '</b></a></td></tr>'
207
        + '<tr><td>' + mytrans("geocache.type") + '</td><td>' + response.type + '</td></tr>'
208
        + '<tr><td>' + mytrans("geocache.size") + '</td><td>' + response.size2 + '</td></tr>'
209
        + '<tr><td>' + mytrans("geocache.status") + '</td><td>' + response.status + '</td></tr>'
210
        + '<tr><td>' + mytrans("geocache.difficulty") + '</td><td>' + response.difficulty + '/5</td></tr>'
211
        + '<tr><td>' + mytrans("geocache.terrain") + '</td><td>' + response.terrain + '/5</td></tr>'
212
        + '<tr><td>' + mytrans("geocache.finds") + '</td><td>' + response.founds + '</td></tr>'
213
        + '</table>';
214
    return content;
215
};
216
217
218
Okapi.showPopup = function (m, code, siteid) {
219
    'use strict';
220
221
    this.m_popupCacheCode = code;
222
223
    if (!this.m_popup) {
224
        this.m_popup = new google.maps.InfoWindow();
225
    }
226
227
    var self = this,
228
        site = this.m_sites[siteid],
229
        url,
230
        data;
231
232
    url = site.url + 'services/caches/geocache';
233
    data = {
234
        'consumer_key': site.key,
235
        'cache_code': code,
236
        'fields' : 'name|type|status|url|owner|founds|size2|difficulty|terrain|location'
237
    };
238
239
    if (site.proxy) {
240
        data = {
241
            url: url + "?" + $.param(data),
242
        };
243
        url = "proxy2.php";
244
    }
245
246
    $.ajax({
247
        url: url,
248
        dataType: 'json',
249
        data: data,
250
        success: function (response) {
251
            var coords = self.parseLocation(response.location);
252
            self.m_map.setCenter(coords);
253
254
            if (!m) {
255
                m = new google.maps.Marker({
256
                    position: coords,
257
                    map: self.m_map,
258
                    icon: self.icon(response.type)
259
                });
260
                if (self.m_maker) {
261
                    self.m_marker.setMap(null);
262
                }
263
                self.registerPopup(m, code, siteid);
264
                self.m_marker = m;
265
            }
266
267
            self.m_popup.setContent(self.createPopupContent(code, response));
268
            self.m_popup.open(self.m_map, m);
269
        }
270
    });
271
};
272
273
274
Okapi.registerPopup = function (m, code, siteid) {
275
    'use strict';
276
277
    if (!this.m_ready) {
278
        return;
279
    }
280
281
    var self = this;
282
283
    google.maps.event.addListener(m, 'click', function () {
284
        self.showPopup(m, code, siteid);
285
    });
286
};
287
288
289
Okapi.removeMarkers = function () {
290
    'use strict';
291
292
    if (!this.m_ready) {
293
        return;
294
    }
295
296
    this.m_sites.map(function (site) {
297
        var key;
298
        for (key in site.markers) {
299
            if (!site.markers.hasOwnProperty(key)) {
300
                continue;
301
            }
302
            site.markers[key].setMap(null);
303
        }
304
        site.markers = {};
305
    });
306
307
    if (this.m_marker) {
308
        this.m_marker.setMap(null);
309
        delete this.m_marker;
310
        this.m_marker = null;
311
    }
312
};
313
314
315
Okapi.loadBboxSite = function (siteid) {
316
    'use strict';
317
318
    if (!this.m_ready) {
319
        return;
320
    }
321
322
    var self = this,
323
        site = this.m_sites[siteid],
324
        b,
325
        bbox,
326
        url,
327
        data;
328
329
    if (!this.m_enabled) {
330
        site.finished = true;
331
        return;
332
    }
333
334
    if (!site.finished) {
335
        return;
336
    }
337
338
    site.finished = false;
339
340
    b = this.m_map.getBounds();
341
    bbox = b.getSouthWest().lat() + "|" + b.getSouthWest().lng() + "|" + b.getNorthEast().lat() + "|" + b.getNorthEast().lng();
342
343
    url = site.url + 'services/caches/shortcuts/search_and_retrieve';
344
    data = {
345
        'consumer_key': site.key,
346
        'search_method': 'services/caches/search/bbox',
347
        'search_params': '{"bbox" : "' + bbox + '", "limit" : "500"}',
348
        'retr_method': 'services/caches/geocaches',
349
        'retr_params': '{"fields": "code|name|location|type|status|url"}',
350
        'wrap': 'false'
351
    };
352
353
    if (site.proxy) {
354
        data = {
355
            url: url + "?" + $.param(data),
356
        };
357
        url = "proxy2.php";
358
    }
359
360
    $.ajax({
361
        url: url,
362
        dataType: 'json',
363
        data: data,
364
        success: function (response) {
365
            var addedCaches = {},
366
                cache,
367
                code;
368
369
            for (code in response) {
370
                if (!response.hasOwnProperty(code)) {
371
                    continue;
372
                }
373
374
                cache = response[code];
375
                if (cache.status !== "Available") {
376
                    continue;
377
                }
378
379
                addedCaches[cache.code] = true;
380
                if (site.markers[cache.code] !== undefined) {
381
                    continue;
382
                }
383
384
                site.markers[cache.code] = new google.maps.Marker({
385
                    position: self.parseLocation(cache.location),
386
                    map: self.m_map,
387
                    icon: self.icon(cache.type)
388
                });
389
390
                self.registerPopup(site.markers[cache.code], cache.code, siteid);
391
            }
392
393
            for (code in site.markers) {
394
                if (site.markers.hasOwnProperty(code) && addedCaches[code] === undefined) {
395
                    site.markers[code].setMap(null);
396
                    delete site.markers[code];
397
                }
398
            }
399
            site.finished = true;
400
        },
401
        error: function () {
402
            site.markers = {};
403
            site.finished = true;
404
        }
405
    });
406
};
407
408
409
Okapi.loadBbox = function () {
410
    'use strict';
411
412
    if (!this.m_ready) {
413
        return;
414
    }
415
416
    var self = this;
417
    this.m_sites.map(function (site) {
418
        self.loadBboxSite(site.siteid);
419
    });
420
};
421
422
423
Okapi.unscheduleLoad = function () {
424
    'use strict';
425
426
    if (!this.m_ready) {
427
        return;
428
    }
429
430
    if (this.m_timer) {
431
        window.clearTimeout(this.m_timer);
432
        this.m_timer = null;
433
    }
434
};
435
436
437
Okapi.scheduleLoad = function () {
438
    'use strict';
439
440
    if (!this.m_ready) {
441
        return;
442
    }
443
444
    var self = this;
445
446
    this.unscheduleLoad();
447
    this.m_timer = window.setTimeout(function () {
448
        self.loadBbox();
449
    }, 500);
450
};
451
452
453
Okapi.toggle = function (t) {
454
    'use strict';
455
456
    Cookies.set('load_caches', t ? "1" : "0", {expires: 30});
457
    if ($('#geocaches').is(':checked') !== t) {
458
        $('#geocaches').attr('checked', t);
459
    }
460
461
    if (this.m_enabled !== t) {
462
        this.m_enabled = t;
463
    }
464
465
    if (this.m_enabled) {
466
        this.setupIcons();
467
        this.setupSites();
468
        this.scheduleLoad();
469
    } else {
470
        this.unscheduleLoad();
471
        this.removeMarkers();
472
    }
473
};
474
475
476
Okapi.restore = function (defaultValue) {
477
    'use strict';
478
479
    var state = get_cookie_string("load_caches", "invalid");
480
481
    if (state === "0") {
482
        this.toggle(false);
483
    } else if (state === "1") {
484
        this.toggle(true);
485
    } else {
486
        this.toggle(defaultValue);
487
    }
488
};
489